<?php
namespace Communal\Controller;
use Common\Controller\CommonController;

/**
 * Turn模块
 */
class TurnController extends CommonController {
	
	protected function _initialize(){
		parent::_initialize();
	}
	
	
	
	/**
	 * coTurn 连接信息接口(TURN API)
	 */
	public function turnAction(){
		$username = I('request.username');
		$key = I('request.key');
		$this->_turn($username , $key);
	}
	
	private function _turn($username , $key){
		$data['username'] = (time()+86400) . ":" . $username;
		$data['password'] = base64_encode(hash_hmac('sha1' , $data['username'] , $key , true));
		$data['ttl'] = 86400;
		$data['uris'][] = C('WEBRTC_TURN_SERVER') . "?transport=udp";
		$data['uris'][] = C('WEBRTC_TURN_SERVER') . "?transport=tcp";
		
		//$this->data = $data;
		//$this->outPut();
		$this->ajaxReturn($data);
	}
    
}
